import API from '@/config/api.js'
import * as qiniu from 'qiniu-js'

const FILE_HOST_URL = 'http://ogay6cpdg.bkt.clouddn.com/'

async function uploadFileToQiNiu (file, key) {
  const response = await API.getQiNiuToken()
  const token = response.data
  const config = {
    useCdnDomain: true
  }
  const putExtra = {
    fname: '',
    params: {},
    mimeType: [] || null
  }

  let observable = qiniu.upload(file, key, token, putExtra, config)
  observable.subscribe(undefined, undefined, async (res) => {
    console.log(res)
    return API.getDownloadUrl(FILE_HOST_URL + res.key)
  }) // 上传开始
}

export default {
  uploadFileToQiNiu
}
